package com.itheima.wisdomnext.mapper;

import com.itheima.wisdomnext.entity.Administrator;
import org.apache.ibatis.annotations.*;

@Mapper
public interface AdministratorMapper {

    // 根据用户名查找管理员
    @Select("SELECT * FROM administrators WHERE username = #{username}")
    Administrator findByUsername(@Param("username") String username);

    // 检查管理员用户名是否存在
    @Select("SELECT COUNT(1) > 0 FROM administrators WHERE username = #{username}")
    boolean existsByUsername(@Param("username") String username);

    // 插入新管理员
    @Insert("INSERT INTO administrators (adminid, username, password, role, is_active) " +
            "VALUES (#{adminId}, #{username}, #{password}, #{role}, #{isActive})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertAdministrator(Administrator admin);
}
